﻿@using OBUCare.Core.Models
@using OBUCare.Web.Models
@using OBUCare.Web.Infrastructure
@{
    var menuName = PageData["moduleID"];
    ViewData["menuName"] = menuName;
}
<h2>@ViewBag.Title</h2>
<link href="../../Content/tableCss.css" rel="stylesheet" type="text/css" />
<table width="100%">
    <tr>
        <td style="text-align:center">
            <span class="pTitle">录入发票明细查询</span>
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <td style="text-align:center">
            @Html.Partial("_InvoiceSearch")
        </td>
    </tr>
    <tr>
        <td style="text-align:center">
            @(Html.Telerik().Grid<View_Invoice_Info>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.SERIAL_NO))
        .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select("ListInvoiceSqlItems", "Report", new { sql = "" })
                    )
        .Columns(columns =>
        {
            columns.Bound(o => o.SERIAL_NO).Title("序号").ClientTemplate("<#= ++index #>").Width("5%");
            columns.Bound(o => o.SERIAL_NO).Width("15%");
            columns.Bound(o => o.USER_NO).Width("8%");
            columns.Bound(o => o.USERNAME).Width("10%");
            columns.Bound(o => o.InvoiceType_Title).Width("8%");
            columns.Bound(o => o.AMOUNT).Width("8%");
            columns.Bound(o => o.INVOICE_NO).Width("8%");
            columns.Bound(o => o.INCOICE_TIME).Width("8%");
            columns.Bound(o => o.OPERATOR_NO).Width("8%");
            columns.Bound(o => o.OPERATOR_NAME).Width("10%");
            columns.Bound(o => o.AGENT_NAME).Width("8%");
        }).TableHtmlAttributes(new { @style = "width:180%" })
        .ClientEvents(events =>
        {
            events.OnError("onError");
            events.OnDataBinding("onDataBinding");
        })
        .Pageable(paging =>
        {
            paging.Style(CommonStyleForUI.Grid_PageStyle)
            .Position(CommonStyleForUI.Grid_PagePosition)
            .PageTo(CommonStyleForUI.Grid_CurrentPage)
            .PageSize(CommonStyleForUI.Grid_PageSize);
        })
        //.Resizable(resizing => resizing.Columns(true))
        .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height))
                    //.Selectable()
)
        </td>
    </tr>
</table>
<script type="text/javascript">
    function onError(e) {
        //debugger;
        e.preventDefault();
        /*if (e.XMLHttpRequest.status == "505")
        alert("系统字段不允许删除");
        else if (e.XMLHttpRequest.status == "506")
        alert("系统表不允许删除");
        else*/
        alert(e.XMLHttpRequest.getResponseHeader("message"));
    }

    var index = 0;

    function onDataBinding(e) {
        var grid = $('#Grid').data('tGrid')
        index = (grid.currentPage - 1) * grid.pageSize;
        e.data = {
            // the key ("category") specifies the variable name of the action method which will contain the specified value
            searchSql: $('#searchSql').val(),
            agentNO: $('#agentNO').val(),
            menuNames: $('#menuNames').val()
        };
    }
</script>
